package com.calculate.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.calculate.entity.Calculate;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

public class CalculateAction implements Action {
	private Calculate calculate;
	private List<Calculate> history = new ArrayList<Calculate>();

	public Calculate getCalculate() {
		return calculate;
	}

	public void setCalculate(Calculate calculate) {
		this.calculate = calculate;
	}

	@Override
	public String execute() throws Exception {
		calculate.setResult(Math.pow(calculate.getNum1(), calculate.getNum2()));
		calculate.setTime(new Date());
		history.add(calculate);
		ActionContext.getContext().getSession().put("history", history);
		System.out.println(history);
		return Action.SUCCESS;
	}

}
